package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.rewardcoin.LogisticsResult;

import java.util.List;

/**
 * Created by Administrator on 2017/3/31.
 */

public class LogisticsAdapter extends BaseAdapter {
    private Context context;
    private List<LogisticsResult.Traces> traces;

    public LogisticsAdapter(Context context, List<LogisticsResult.Traces> traces) {
        this.context = context;
        this.traces = traces;
    }

    @Override
    public int getCount() {
        return traces.size();
    }

    @Override
    public Object getItem(int position) {
        return traces.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try{
            ViewHolder holder = null;
            if(convertView==null){
                holder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.item_lvlogistics, parent, false);
                holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
                holder.tvPos = (TextView) convertView.findViewById(R.id.tvPos);
                holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }
            if(position==0){
                holder.ivImg.setImageResource(R.mipmap.iv_red_circle);
            }else{
                holder.ivImg.setImageResource(R.mipmap.iv_logistics_up);
            }
            if(null!=traces.get(traces.size()-position-1)&&!"".equals(traces.get(traces.size()-position-1))){
                LogisticsResult.Traces data = traces.get(traces.size()-position-1);
                if(null!=data.getAcceptStation()&&!"".equals(data.getAcceptStation())){
                    holder.tvPos.setText(data.getAcceptStation());
                }else{
                    holder.tvPos.setText("**");
                }
                if(null!=data.getAcceptTime()&&!"".equals(data.getAcceptTime())){
                    holder.tvTime.setText(data.getAcceptTime());
                }else{
                    holder.tvTime.setText("**");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return convertView;
    }

    class ViewHolder{
        private TextView tvPos;
        private TextView tvTime;
        private ImageView ivImg;
    }
}
